package cn.com.thinvent.dispatch.web.controller;

import cn.com.thinvent.dispatch.entity.ModelUser;
import cn.com.thinvent.dispatch.entity.response.ReturnModel;
import cn.com.thinvent.dispatch.service.biz.UserService;

import cn.com.thinvent.dispatch.web.utils.UserContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 用户controller
 */
@Api(description = "user模块")
@Controller
@RequestMapping("/user")
@CrossOrigin(origins = "*")
@ResponseBody
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    @ResponseBody
    @ApiOperation(value = "登录接口")
    public ReturnModel login(@RequestBody ModelUser modelUser) {
        System.out.println(modelUser);
        ModelUser login = userService.login(modelUser);
        return new ReturnModel(200, login, "");
    }

    @GetMapping("/health")
    @ResponseBody
    public ReturnModel health() {
        Integer id = UserContext.get();
        return new ReturnModel(200, id, "");
    }


}
